package com.guichun.insert;

import com.guichun.Jdbcs;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @author guichun
 * @version 1.0.0
 * @ClassName JdbcIn.java
 * @email onebigbai@icloud.com
 * @Description JDBC新增数据
 * @createTime 2021-03-09
 */
public class JdbcIn {

    public JdbcIn(Jdbcs jdbcs) {
        try {
            Connection connection = DriverManager.getConnection(jdbcs.getJdbcUrl(), jdbcs.getJdbcRoot(), jdbcs.getJdbcPassword());

            PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO students (id, name , grade, gender)VALUES (?,?,?,?)");
            preparedStatement.setObject(1,35);
            preparedStatement.setObject(2,"guichun5");
            preparedStatement.setObject(3,1);
            preparedStatement.setObject(4,0);

            int update = preparedStatement.executeUpdate();
            System.out.println("update = " + update);

            connection.close();
        }catch (SQLException e) {
            System.out.println("e = " + e);
        }
    }
}
